<template>
    <div class="main-box-right">
         <el-dialog
            :title="operateType"
            :visible.sync="isShow"
            >
            <template >
                <imagecropper  v-if="isShow" @getimage="getimage"  :shopinfo="shop" />
                  <div slot="footer" class="dialog-footer">
                    <el-button size="medium" type="primary" @click="edithead(shop.shopId)">上传</el-button>
                    <el-button size="medium" @click="isShow = false">取消</el-button>
                  </div>
            </template>
          </el-dialog>
                <div class="main-box-right-top" v-for="val in shopinfo" :key="val.shopId">
                    <h2>店铺名称: {{val.shopName}}</h2>
                    <p>图片信息</p>
                    <div class="main-box-right-part">
                        <p>封面</p>
                        <img :src="val.shopCover" class="img" >
                        <button @click="modifyHeadimg(val)">修改</button>
                    </div>
                </div>
      </div>
</template>

<script>
import {updateheadimg,getshopByid} from '../../../api/personalData/shop/index'
import jwtDecode from 'jwt-decode'
import cookie from '../../cookie/index'
import imagecropper from '@/components/ly/Common/imagecropper'
export default {
    name:'ShopPicture',
    components:{imagecropper},
    data() {
      return {
        shopinfo:{},
        files:"",
        operateType:'add',
        isShow:false,
        shop:''
      }
    },
    methods:{
       // 获取剪裁的文件
      getimage(data){
        console.log(data);
        this.files = data
      },
      edithead(shopId){
        console.log(shopId);
       const formdata = new FormData();
        formdata.append("newStoreCover", this.files);
        updateheadimg({storeId:shopId},formdata).then(data=>{
           const list = data.data.message
              if(list === '成功'){
                this.isShow =false
                  this.$message({
                        type: "success",
                        message: "修改封面成功!"
                    })
                    console.log('修改成',data);
                    this.getShopinfo();
              }else{
                 this.$message.error('上传封面失败');
              }
        })
      },
      modifyHeadimg(val){
        console.log(val);
        this.shop = val
        this.isShow =true
      },
      // 店铺信息
       getShopinfo(){
          const user = jwtDecode(cookie.getToken());
          getshopByid({userId:user.userId}).then(data=>{
             const list =data.data.data
             this.shopinfo = list
             console.log('@@',list);
        })
      }
    },
    created(){
      this.getShopinfo();
    }
}
</script>

<style lang="less" scoped>
@navcolor: rgb(58, 58, 58);
@navfont: 13px;
@width: 1200px;
@hovercolor: #76d4ff;
* {
  margin: 0;
  padding: 0;
}
a {
  text-decoration: none;
}
input {
  outline: none;
}
li {
  list-style: none;
}
.main-box-right {
      margin-left: 20px;
      float: left;
      width: 90%;
      border-radius: 4px;
      background-color: #ffffff;
      border: 1px solid #e5e5e5;
      margin-bottom: 10px;
      position: relative;
      .main-box-right-top {
        width: 100%;
        // height: 90px;
        h2 {
          margin-top: 10px;
          font-weight: 400;
          padding: 12px 30px;
          font-size: 20px;
        }
        p {
          font-size: 14px;
          padding-left: 32px;
          margin-bottom: 20px;
          color: #838383;
        }
        .main-box-right-part {
          width: 90%;
          height: 200px;
          margin: 0 auto;
          border-top: 1px solid #d6d6d6;
          position: relative;
          p {
            width: 103px;
            display: inline-block;
            text-align: right;
            line-height: 200px;
            font-weight: 400;
            font-size: 18px;
            color: #333333;
            &::after {
              content: "";
              height: 100%;
              padding-right: 30px;
              border-right: 2px solid #d6d6d6;
            }
          }
          span {
            margin-left: 30px;
            font-size: 12px;
            color: #666666;
            line-height: 40px;
          }
          button {
            background: #ffffff;
            border: 1px solid #e5e5e5;
            border-radius: 100px;
            font-size: 14px;
            color: #666666;
            float: right;
            height: 40px;
            width: 82px;
            cursor: pointer;
            margin-top: 80px;
            text-align: center;
          }
          .img {
              cursor: pointer;
              // width: 180px;
              height: 180px;
            position: absolute;
            top: 10px;
            left: 170px;
          }
        }
      }
    }
</style>